'\" t
.TH "SYSTEMD\-REPART" "8" "" "systemd 249" "systemd-repart"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
systemd-repart, systemd-repart.service \- Automatically grow and add partitions
.SH "SYNOPSIS"
.HP \w'\fBsystemd\-repart\fR\ 'u
\fBsystemd\-repart\fR [OPTIONS...] [\fI[BLOCKDEVICE]\fR...]
.PP
systemd\-repart\&.service
.SH "DESCRIPTION"
.PP
\fBsystemd\-repart\fR
grows and adds partitions to a partition table, based on the configuration files described in
\fBrepart.d\fR(5)\&.
.PP
If invoked with no arguments, it operates on the block device backing the root file system partition of the running OS, thus growing and adding partitions of the booted OS image itself\&. If
\fI\-\-image=\fR
is used it will operate on the specified image file\&. When called in the
"initrd"
it operates on the block device backing
/sysroot/
instead, i\&.e\&. on the block device the system will soon transition into\&. The
systemd\-repart\&.service
service is generally run at boot in the initial RAM disk, in order to augment the partition table of the OS before its partitions are mounted\&.
\fBsystemd\-repart\fR
(mostly) operates in a purely incremental mode: it only grows existing and adds new partitions; it does not shrink, delete or move existing partitions\&. The service is intended to be run on every boot, but when it detects that the partition table already matches the installed
repart\&.d/*\&.conf
configuration files, it executes no operation\&.
.PP
\fBsystemd\-repart\fR
is intended to be used when deploying OS images, to automatically adjust them to the system they are running on, during first boot\&. This way the deployed image can be minimal in size and may be augmented automatically at boot when needed, taking possession of disk space available but not yet used\&. Specifically the following use cases are among those covered:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
The root partition may be grown to cover the whole available disk space\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
A
/home/, swap or
/srv/
partition can be added\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
A second (or third, \&...) root partition may be added, to cover A/B style setups where a second version of the root file system is alternatingly used for implementing update schemes\&. The deployed image would carry only a single partition ("A") but on first boot a second partition ("B") for this purpose is automatically created\&.
.RE
.PP
The algorithm executed by
\fBsystemd\-repart\fR
is roughly as follows:
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
The
repart\&.d/*\&.conf
configuration files are loaded and parsed, and ordered by filename (without the directory prefix)\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.2
.\}
The partition table already existing on the block device is loaded and parsed\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 3.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  3." 4.2
.\}
The existing partitions in the partition table are matched up with the
repart\&.d/*\&.conf
files by GPT partition type UUID\&. The first existing partition of a specific type is assigned the first configuration file declaring the same type\&. The second existing partition of a specific type is then assigned the second configuration file declaring the same type, and so on\&. After this iterative assigning is complete any left\-over existing partitions that have no matching configuration file are considered "foreign" and left as they are\&. And any configuration files for which no partition currently exists are understood as a request to create such a partition\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 4.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  4." 4.2
.\}
Taking the size constraints and weights declared in the configuration files into account, all partitions that shall be created are now allocated to the disk, taking up all free space, always respecting the size and padding requests\&. Similar, existing partitions that are determined to grow are grown\&. New partitions are always appended to the end of the existing partition table, taking the first partition table slot whose index is greater than the indexes of all existing partitions\&. Partition table slots are never reordered and thus partition numbers are ensured to remain stable\&. Note that this allocation happens in RAM only, the partition table on disk is not updated yet\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 5.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  5." 4.2
.\}
All existing partitions for which configuration files exist and which currently have no GPT partition label set will be assigned a label, either explicitly configured in the configuration or (if that\*(Aqs missing) derived automatically from the partition type\&. The same is done for all partitions that are newly created\&. These assignments are done in RAM only, too, the disk is not updated yet\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 6.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  6." 4.2
.\}
Similarly, all existing partitions for which configuration files exist and which currently have an all\-zero identifying UUID will be assigned a new UUID\&. This UUID is cryptographically hashed from a common seed value together with the partition type UUID (and a counter in case multiple partitions of the same type are defined), see below\&. The same is done for all partitions that are created anew\&. These assignments are done in RAM only, too, the disk is not updated yet\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 7.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  7." 4.2
.\}
Similarly, if the disk\*(Aqs volume UUID is all zeroes it is also initialized, also cryptographically hashed from the same common seed value\&. Also, in RAM only, too\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 8.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  8." 4.2
.\}
The disk space assigned to new partitions (i\&.e\&. what was previously considered free space but is no longer) is now erased\&. Specifically, all file system signatures are removed, and if the device supports it the
\fBBLKDISCARD\fR
I/O control command is issued to inform the hardware that the space is empty now\&. In addition any "padding" between partitions and at the end of the device is similarly erased\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 9.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  9." 4.2
.\}
The new partition table is finally written to disk\&. The kernel is asked to reread the partition table\&.
.RE
.PP
As exception to the normally strictly incremental operation, when called in a special "factory reset" mode,
\fBsystemd\-repart\fR
may also be used to erase existing partitions to reset an installation back to vendor defaults\&. This mode of operation is used when either the
\fB\-\-factory\-reset=yes\fR
switch is passed on the tool\*(Aqs command line, or the
\fBsystemd\&.factory_reset=yes\fR
option specified on the kernel command line, or the
\fIFactoryReset\fR
EFI variable (vendor UUID
\fB8cf2644b\-4b0b\-428f\-9387\-6d876050dc67\fR) is set to "yes"\&. It alters the algorithm above slightly: between the 3rd and the 4th step above any partition marked explicitly via the
\fIFactoryReset=\fR
boolean is deleted, and the algorithm restarted, thus immediately re\-creating these partitions anew empty\&.
.PP
Note that
\fBsystemd\-repart\fR
only changes partition tables, it does not create or resize any file systems within these partitions\&. A separate mechanism should be used for that, for example
\fBsystemd-growfs\fR(8)
and
\fBsystemd\-makefs\fR\&.
.PP
The UUIDs identifying the new partitions created (or assigned to existing partitions that have no UUID yet), as well as the disk as a whole are hashed cryptographically from a common seed value\&. This seed value is usually the
\fBmachine-id\fR(5)
of the system, so that the machine ID reproducibly determines the UUIDs assigned to all partitions\&. If the machine ID cannot be read (or the user passes
\fB\-\-seed=random\fR, see below) the seed is generated randomly instead, so that the partition UUIDs are also effectively random\&. The seed value may also be set explicitly, formatted as UUID via the
\fB\-\-seed=\fR
option\&. By hashing these UUIDs from a common seed images prepared with this tool become reproducible and the result of the algorithm above deterministic\&.
.PP
The positional argument should specify the block device to operate on\&. Instead of a block device node path a regular file may be specified too, in which case the command operates on it like it would if a loopback block device node was specified with the file attached\&. If
\fB\-\-empty=create\fR
is specified the specified path is created as regular file, which is useful for generating disk images from scratch\&.
.SH "OPTIONS"
.PP
The following options are understood:
.PP
\fB\-\-dry\-run=\fR
.RS 4
Takes a boolean\&. If this switch is not specified
\fB\-\-dry\-run=yes\fR
is the implied default\&. Controls whether
systemd\-repart
executes the requested re\-partition operations or whether it should only show what it would do\&. Unless
\fB\-\-dry\-run=no\fR
is specified
systemd\-repart
will not actually touch the device\*(Aqs partition table\&.
.RE
.PP
\fB\-\-empty=\fR
.RS 4
Takes one of
"refuse",
"allow",
"require",
"force"
or
"create"\&. Controls how to operate on block devices that are entirely empty, i\&.e\&. carry no partition table/disk label yet\&. If this switch is not specified the implied default is
"refuse"\&.
.sp
If
"refuse"
\fBsystemd\-repart\fR
requires that the block device it shall operate on already carries a partition table and refuses operation if none is found\&. If
"allow"
the command will extend an existing partition table or create a new one if none exists\&. If
"require"
the command will create a new partition table if none exists so far, and refuse operation if one already exists\&. If
"force"
it will create a fresh partition table unconditionally, erasing the disk fully in effect\&. If
"force"
no existing partitions will be taken into account or survive the operation\&. Hence: use with care, this is a great way to lose all your data\&. If
"create"
a new loopback file is create under the path passed via the device node parameter, of the size indicated with
\fB\-\-size=\fR, see below\&.
.RE
.PP
\fB\-\-discard=\fR
.RS 4
Takes a boolean\&. If this switch is not specified
\fB\-\-discard=yes\fR
is the implied default\&. Controls whether to issue the
\fBBLKDISCARD\fR
I/O control command on the space taken up by any added partitions or on the space in between them\&. Usually, it\*(Aqs a good idea to issue this request since it tells the underlying hardware that the covered blocks shall be considered empty, improving performance\&. If operating on a regular file instead of a block device node, a sparse file is generated\&.
.RE
.PP
\fB\-\-size=\fR
.RS 4
Takes a size in bytes, using the usual K, M, G, T suffixes, or the special value
"auto"\&. If used the specified device node path must refer to a regular file, which is then grown to the specified size if smaller, before any change is made to the partition table\&. If specified as
"auto"
the minimal size for the disk image is automatically determined (i\&.e\&. the minimal sizes of all partitions are summed up, taking space for additional metadata into account)\&. This switch is not supported if the specified node is a block device\&. This switch has no effect if the file is already as large as the specified size or larger\&. The specified size is implicitly rounded up to multiples of 4096\&. When used with
\fB\-\-empty=create\fR
this specifies the initial size of the loopback file to create\&.
.sp
The
\fB\-\-size=auto\fR
option takes the sizes of pre\-existing partitions into account\&. However, it does not accommodate for partition tables that are not tightly packed: the configured partitions might still not fit into the backing device if empty space exists between pre\-existing partitions (or before the first partition) that cannot be fully filled by partitions to grow or create\&.
.sp
Also note that the automatic size determination does not take files or directories specified with
\fBCopyFiles=\fR
into account: operation might fail if the specified files or directories require more disk space then the configured per\-partition minimal size limit\&.
.RE
.PP
\fB\-\-factory\-reset=\fR
.RS 4
Takes boolean\&. If this switch is not specified
\fB\-\-factory=reset=no\fR
is the implied default\&. Controls whether to operate in "factory reset" mode, see above\&. If set to true this will remove all existing partitions marked with
\fIFactoryReset=\fR
set to yes early while executing the re\-partitioning algorithm\&. Use with care, this is a great way to lose all your data\&. Note that partition files need to explicitly turn
\fIFactoryReset=\fR
on, as the option defaults to off\&. If no partitions are marked for factory reset this switch has no effect\&. Note that there are two other methods to request factory reset operation: via the kernel command line and via an EFI variable, see above\&.
.RE
.PP
\fB\-\-can\-factory\-reset\fR
.RS 4
If this switch is specified the disk is not re\-partitioned\&. Instead it is determined if any existing partitions are marked with
\fIFactoryReset=\fR\&. If there are the tool will exit with exit status zero, otherwise non\-zero\&. This switch may be used to quickly determine whether the running system supports a factory reset mechanism built on
\fBsystemd\-repart\fR\&.
.RE
.PP
\fB\-\-root=\fR
.RS 4
Takes a path to a directory to use as root file system when searching for
repart\&.d/*\&.conf
files, for the machine ID file to use as seed and for the
\fICopyFiles=\fR
and
\fICopyBlocks=\fR
source files and directories\&. By default when invoked on the regular system this defaults to the host\*(Aqs root file system
/\&. If invoked from the initial RAM disk this defaults to
/sysroot/, so that the tool operates on the configuration and machine ID stored in the root file system later transitioned into itself\&.
.RE
.PP
\fB\-\-image=\fR
.RS 4
Takes a path to a disk image file or device to mount and use in a similar fashion to
\fB\-\-root=\fR, see above\&.
.RE
.PP
\fB\-\-seed=\fR
.RS 4
Takes a UUID as argument or the special value
\fBrandom\fR\&. If a UUID is specified the UUIDs to assign to partitions and the partition table itself are derived via cryptographic hashing from it\&. If not specified it is attempted to read the machine ID from the host (or more precisely, the root directory configured via
\fB\-\-root=\fR) and use it as seed instead, falling back to a randomized seed otherwise\&. Use
\fB\-\-seed=random\fR
to force a randomized seed\&. Explicitly specifying the seed may be used to generated strictly reproducible partition tables\&.
.RE
.PP
\fB\-\-pretty=\fR
.RS 4
Takes a boolean argument\&. If this switch is not specified, it defaults to on when called from an interactive terminal and off otherwise\&. Controls whether to show a user friendly table and graphic illustrating the changes applied\&.
.RE
.PP
\fB\-\-definitions=\fR
.RS 4
Takes a file system path\&. If specified the
*\&.conf
files are read from the specified directory instead of searching in
/usr/lib/repart\&.d/*\&.conf,
/etc/repart\&.d/*\&.conf,
/run/repart\&.d/*\&.conf\&.
.RE
.PP
\fB\-\-key\-file=\fR
.RS 4
Takes a file system path\&. Configures the encryption key to use when setting up LUKS2 volumes configured with the
\fIEncrypt=key\-file\fR
setting in partition files\&. Should refer to a regular file containing the key, or an
\fBAF_UNIX\fR
stream socket in the file system\&. In the latter case a connection is made to it and the key read from it\&. If this switch is not specified the empty key (i\&.e\&. zero length key) is used\&. This behaviour is useful for setting up encrypted partitions during early first boot that receive their user\-supplied password only in a later setup step\&.
.RE
.PP
\fB\-\-tpm2\-device=\fR, \fB\-\-tpm2\-pcrs=\fR
.RS 4
Configures the TPM2 device and list of PCRs to use for LUKS2 volumes configured with the
\fIEncrypt=tpm2\fR
option\&. These options take the same parameters as the identically named options to
\fBsystemd-cryptenroll\fR(1)
and have the same effect on partitions where TPM2 enrollment is requested\&.
.RE
.PP
\fB\-h\fR, \fB\-\-help\fR
.RS 4
Print a short help text and exit\&.
.RE
.PP
\fB\-\-version\fR
.RS 4
Print a short version string and exit\&.
.RE
.PP
\fB\-\-no\-pager\fR
.RS 4
Do not pipe output into a pager\&.
.RE
.PP
\fB\-\-no\-legend\fR
.RS 4
Do not print the legend, i\&.e\&. column headers and the footer with hints\&.
.RE
.PP
\fB\-\-json=\fR\fIMODE\fR
.RS 4
Shows output formatted as JSON\&. Expects one of
"short"
(for the shortest possible output without any redundant whitespace or line breaks),
"pretty"
(for a pretty version of the same, with indentation and line breaks) or
"off"
(to turn off JSON output, the default)\&.
.RE
.SH "EXIT STATUS"
.PP
On success, 0 is returned, a non\-zero failure code otherwise\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBrepart.d\fR(5),
\fBmachine-id\fR(5),
\fBsystemd-cryptenroll\fR(1)
